package org.hales.controller.excel;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.hales.service.PetrolStationService;
import org.hales.vo.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import java.io.IOException;

/**
 * @author 陈建康
 */
/*@Validated
@RestController
@RequestMapping("/read/Excel")
@Api(description = "excel读取")*/
public class ReadController {
    @Autowired
    private PetrolStationService petrolStationService;
    @PostMapping(value = "/readExcel/fuelGun")
    @ApiOperation("读取加油枪excel")
    public ServerResponse<String> readFuelGunInfoExcel(
            @ApiParam(value = "工作表sheet序号(索引从0开始)")@RequestParam(value = "sheetIndex",required = false,defaultValue = "0") int sheetIndex,
            @ApiParam(value = "标题行序号(索引从0开始)" )@RequestParam(value = "headIndex",defaultValue = "0",required = false) int headIndex,
            @ApiParam(value = "上传的加油枪Excel附件",required = true) @NotNull(message = "上传的附件不能为空") @RequestParam("file") MultipartFile file) throws IOException {
        petrolStationService.saveFuelGum(file,sheetIndex,headIndex);
        return ServerResponse.createBySuccess("文件读取成功");
    }
    @PostMapping(value = "/readExcel/petrolStation")
    @ApiOperation("读取加油站excel")
    public ServerResponse<String> readPetrolStationInfoExcel(
            @ApiParam(value = "工作表sheet序号(索引从0开始)")@RequestParam(value = "sheetIndex",required = false,defaultValue = "0") int sheetIndex,
            @ApiParam(value = "标题行序号(索引从0开始)" )@RequestParam(value = "headIndex",defaultValue = "0",required = false) int headIndex,
            @ApiParam(value = "上传的加油站Excel附件",required = true) @NotNull(message = "上传的附件不能为空") @RequestParam("file") MultipartFile file
                                                             ) throws IOException {
        petrolStationService.savePetrolStation(file,sheetIndex,headIndex);
        return ServerResponse.createBySuccess("文件读取成功");
    }
}
